<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <TableHeader
            :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch', 'quickSearch', 'columnDisplay']"
            :quick-search-placeholder="t('quick Search Placeholder', { fields: t('xRepairrecord.quick Search Fields') })"
        />

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef" />

        <!-- 表单 -->
        <PopupForm />
    </div>
</template>

<script setup lang="ts">
import { ref, provide, onMounted, getCurrentInstance } from 'vue'
import baTableClass from '/@/utils/baTable'
import { xRepairrecord } from '/@/api/controllerUrls'
import { defaultOptButtons } from '/@/components/table'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'
import PopupForm from './popupForm.vue'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'

const { t } = useI18n()
const tableRef = ref()
const route = useRoute()
const optButtons = defaultOptButtons(route.name=='xRepairrecord/report'?["edit","delete"]:["edit"])

let tableUrl = ''
if(route.name=='xRepairrecord/check'){
    tableUrl = '_h'
}
if(route.name=='xRepairrecord/approve'){
    tableUrl = '_s'
}
if(route.name=='xRepairrecord/confirm'){
    tableUrl = '_yw'
}
const SJDateShow = ref(false)

const baTable = new baTableClass(
    new baTableApi(xRepairrecord,tableUrl),
    {
        pk: 'BIZNO',
        column: [
            { type: 'selection', align: 'center', operator: false },
            { label: t('xRepairrecord.BIZNO'), prop: 'BIZNO', align: 'center',operator:false },
            { label: t('xRepairrecord.TCNO'), prop: 'TCNO', align: 'center',operator:false },
            { label: t('xRepairrecord.YARD'), prop: 'YARD', align: 'center',operator:false },
            { label: t('xRepairrecord.GJENDDATE'), prop: 'GJENDDATE', align: 'center', render: 'datetime', sortable: 'custom', operator: 'RANGE', width: 160 ,show:false},
            
            { label: t('xRepairrecord.SJENDDATE'), prop: 'SJENDDATE', align: 'center',render: 'customTemplate', customTemplate:(row:any)=>{
                return row.SJENDDATE?'<span>'+row.SJENDDATE.split('.')[0]+'</span>':'<span></span>'
            },  operator: false, width: 160 },
            { label: t('xRepairrecord.RPTYPE'), prop: 'RPTYPE', align: 'center',operator:false },
            { label: t('xRepairrecord.YARDOFFER'), prop: 'YARDOFFER', align: 'center',operator:false },
            { label: t('xRepairrecord.OFFERPATH'), prop: 'OFFERPATH', align: 'center',show:false ,operator:false},
            { label: t('xRepairrecord.TJFLAG'), prop: 'TJFLAG', align: 'center' ,show:false,operator:false},
            { label: t('xRepairrecord.MONEY'), prop: 'MONEY', align: 'center', operator:false },
            { label: t('xRepairrecord.STATUS'), prop: 'STATUS', align: 'center',operator:false },
            { label: t('xRepairrecord.DEPT'), prop: 'DEPTNAME', align: 'center',operator:false },
            { label: t('xRepairrecord.OP'), prop: 'OP', align: 'center',show:false ,operator:false},
            { label: t('xRepairrecord.OPTIME'), prop: 'OPTIME', align: 'center', render: 'datetime', sortable: 'custom', operator:false, width: 160 },
            { label: t('xRepairrecord.PF'), prop: 'PF', align: 'center',show:false,operator:false },
            { label: t('xRepairrecord.PFTIME'), prop: 'PFTIME', align: 'center', render: 'datetime', sortable: 'custom', operator:false, width: 160,show:false },
            { label: t('xRepairrecord.UPLOADER'), prop: 'UPLOADER', align: 'center',show:false,operator:false },
            { label: t('xRepairrecord.UPLOADTIME'), prop: 'UPLOADTIME', align: 'center', render: 'datetime', sortable: 'custom', operator:false, width: 160,show:false },
            { label: t('xRepairrecord.YWY'), prop: 'YWY', align: 'center' ,show:false,operator:false},
            { label: t('xRepairrecord.ZWTYPE'), prop: 'ZWTYPE', align: 'center' ,show:false,operator:false},
            { label: t('xRepairrecord.TZID'), prop: 'TZID', align: 'center' ,show:false,operator:false},
            { label: t('xRepairrecord.SJENDDATE'), prop: 'SJENDDATE', align: 'center',render: 'datetime', operator: 'RANGE', width: 160,show:false },
            { label: '核价状态', prop: 'TJFLAG', align: 'center',render:'tag',replaceValue:{null:'未提交','1':'已提交'},show:route.name=='xRepairrecord/report',operator:false},
            { label: '审批状态', prop: 'statuss', align: 'center',render:'tag',show:route.name !=='xRepairrecord/report',operator:'=',replaceValue:{'未发起':'未发起','待审批':'待审批','已审批':'已审批','已退回':'已退回','已完成':'已完成'}},
            { label: t('operate'), align: 'center', width: 100, render: 'buttons', buttons: optButtons, operator: false },
        ],
        dblClickNotEditColumn: [undefined, ],
        defaultOrder: { prop: 'BIZNO', order: 'desc' },
    },
    {
        defaultItems: [],
    },{
        getIndex:()=>{
            SJDateShow.value = false
            return true
        }
    },{
        getIndex:(()=>{
            SJDateShow.value = true
        })
    }
)

provide('baTable', baTable)

onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    baTable.getIndex()?.then(() => {
        baTable.initSort()
        baTable.dragSort()
    })
})
</script>

<script lang="ts">
import { defineComponent } from 'vue'
import { useRoute } from 'vue-router'
import router from '/@/router'
export default defineComponent({
    name: 'xRepairrecord',
})
</script>

<style scoped lang="scss"></style>
